//
//  ZacollectModel.swift
//  todoios
//
//  Created by qianli on 2025/7/15.
//

import Foundation
import UIKit
import Moya
import SwiftyUserDefaults

class ZacollectModel{
    static let shared = ZacollectModel()
    private static let logger = NetworkLoggerPlugin(configuration: .init(logOptions: .verbose))
    private let VJKiXGtGCvnK5PQd = MoyaProvider<APIHub>(plugins: [logger])
    
    
    func vnveDBhaItvpywSl(eventDict:[String: Any]){//completion: @escaping (Result<BaseData, Error>) -> Void
        self.VJKiXGtGCvnK5PQd.request(.apiZaCollect(eventData: eventDict)){ result in
            switch result{
            case .success(let response):
                if response.statusCode == 200{
                    print("zaCollect:OK")
                }else{
                    print("zaCollect>Fail:\(response.statusCode)")
                }
                 
            case .failure(let error):
                print("zaCollect>err:",error.localizedDescription)
            }
        }
    }
    
    func vnveDBhaItvpywSl(_ eventValue:String,_ errorValue:String){
        var encodeError = errorValue
        if let encodedStr = errorValue.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
            encodeError = encodedStr
        }
        let eventDict = ["event":eventValue,"error":encodeError]
        self.VJKiXGtGCvnK5PQd.request(.apiZaCollect(eventData: eventDict)){ result in
            switch result{
            case .success(let response):
                if response.statusCode == 200{
                    print("zaCollect:OK")
                }else{
                    print("zaCollect>Fail:\(response.statusCode)")
                }
                 
            case .failure(let error):
                print("zaCollect>err:",error.localizedDescription)
            }
        }
    }
    
}
